package com.gy.api.pc.content.controller;


import com.github.pagehelper.PageInfo;
import com.gy.api.base.ApiIndex;
import com.gy.api.base.IDsEntity;
import com.gy.api.base.R;
import com.gy.api.base.RestPage;
import com.gy.api.pc.content.domain.vo.*;
import com.gy.api.pc.content.service.IArticleInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/article/info")
@Api( tags = ApiIndex.ArticleInfoController)
public class ArticleInfoController {

    @Autowired
    private IArticleInfoService service;

    @PostMapping("/page")
    @ApiOperation(value = "文章管理分页列表")
    @ResponseBody
    public R<RestPage<List<ArticleInfoVO>>> getPage(@RequestBody ArticleSearchDto dto) {
        List<ArticleInfoVO> list = service.pageCulvert(dto);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    @PostMapping("/del")
    @ApiOperation(value = "文章删除")
    @ResponseBody
    public R delete(@RequestBody IDsEntity iDsEntity) {
        service.delete(iDsEntity.getIds());
        return new R();
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加文章")
    @ResponseBody
    public R addSave(@RequestBody ArticleInfoAddVO addDto) {
        service.save(addDto);
        return new R();
    }


    @PostMapping("/update")
    @ApiOperation(value = "编辑文章")
    @ResponseBody
    public R update(@RequestBody ArticleInfoUpdateVO addDto) {
        service.update(addDto);
        return new R();
    }

    @GetMapping("/selectById")
    @ApiOperation(value = "查看文章详情")
    @ResponseBody
    public R<ArticleInfoVO> selectById(@RequestParam String id) {
        ArticleInfoVO articleInfo = service.selectById(id);
        return new R(articleInfo);
    }

    @GetMapping("/selectByList")
    @ApiOperation(value = "轮播图列表接口")
    @ResponseBody
    public R<List<ArticleInfoVO>> selectByList() {
        List<ArticleInfoVO> articleInfos = service.selectByList();
        return new R(articleInfos);
    }

}

